/**
 * 
 */
package com.jeearsenal.service;

import java.util.Collection;
import java.util.List;

import com.jeearsenal.model.User;

/**
 * @author ashish.sinha
 *
 */
public class UserService implements IUserService {
	
	private List<User> users;
	
	/**
	 * @return the users
	 */
	public List<User> getUsers() {
		return users;
	}

	/**
	 * @param users the users to set
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}

	/*
	 * (non-Javadoc)
	 * @see test.jee.services.IUserService#countUser()
	 */
	public long countUser() {
		try{
			return users.size();
		}catch(NullPointerException npe){
			npe.printStackTrace();
			return -1;
		}
	}

	/* (non-Javadoc)
	 * @see test.jee.services.IUserService#createUser(test.jee.model.User)
	 */
	public boolean createUser(User user) {
		try{
			if(users.contains(user)==false){
				users.add(user);
				return true;
			}else{
				return false;
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see test.jee.services.IUserService#deleteUser(test.jee.model.User)
	 */
	public boolean deleteUser(User user) {
		try{
			if(users.contains(user)){
				users.remove(user);
				return true;
			}else{
				return false;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see test.jee.services.IUserService#listUser()
	 */
	public Collection<User> listUser() {
		return users;
	}

}
